﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LMS.SMSH.WEB
{
    public partial class AdminTestStuAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //绑定chkBoxListStu数据
                bingchkBoxListStu();
            }
        }

        /// <summary>
        ///  绑定chkBoxListStu数据
        /// </summary>
        private void bingchkBoxListStu()
        {
            chkBoxListStu.DataSource = LMSDataContext.GetLMSDB.TB_Student.Select(stu => stu);
            chkBoxListStu.DataTextField = "stuName";
            chkBoxListStu.DataValueField = "stuNo";
            chkBoxListStu.DataBind();
        }

        /// <summary>
        /// 将选择的学生总数，更新到TB_Project表的StuNo字段
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnOK_Click(object sender, EventArgs e)
        {
            Int32 stuCount = 0;
            for (int i = 0; i < chkBoxListStu.Items.Count; i++)
            {
                if (chkBoxListStu.Items[i].Selected)
                {
                    stuCount++;
                }
            }
            if (Request.QueryString["currentRowID"] != null)
            {
                TB_Project tb_project = LMSDataContext.GetLMSDB.TB_Project.Single(pro => pro.ID == Int32.Parse(Request.QueryString["currentRowID"]));
                tb_project.proStuNo = stuCount;
                LMSDataContext.GetLMSDB.SubmitChanges();
                Response.Redirect("AdmTestItemManange.aspx");
            }

        }



    }
}